package SE2;
//Max

import java.util.GregorianCalendar;

public class ProductionScheduler
{
    private String name;
    private String password;
    private GregorianCalendar lastLogin;
    private int employeeId;
    private ProductionRelease productionRelease = null;

    ProductionScheduler(String name, String password, GregorianCalendar lastLogin)
    {
        this.name = name;
        this.password = password;
        this.lastLogin = lastLogin;
    }

    public boolean storeVehicleConfiguration(VehicleConfiguration vc)
    {
       	DatabaseConnection db = new DatabaseConnection();
       	return db.storeVehicleConfiguration(vc);
    }

    public boolean checkProductionRelease(ProductionRelease pr)
    {
    	this.productionRelease = pr;
    	return productionRelease.checkProductionRelease();	
    }

    public boolean confirmPlan()
    {
    	DatabaseConnection db = null;
    	boolean materialIsOrdered = true; 
    	boolean productionReleaseIsStored = false;
    	
    	if (!productionRelease.getPurchaseList().isEmpty() || productionRelease != null)
    		materialIsOrdered = productionRelease.createOrderingResult();
    	if (materialIsOrdered)
    	{
    		db = new DatabaseConnection();
    		productionReleaseIsStored = db.storeProductionRelease(productionRelease, this.employeeId);
    		if (!productionReleaseIsStored)
    		{
    			productionRelease.addToErrorList(db.getErrors());
    		}
    	}
    	return productionReleaseIsStored;
    }

    public String getName()
    {
        return name;
    }

    public String getPassword()
    {
        return password;
    }
    
    public String getErrors()
    {
    	return productionRelease.getErrors();
    }
    
    public void setEmployeeID(int id)
    {
    	this.employeeId = id;
    }
    
    public int getEmployeeId()
    {
    	return this.employeeId;
    }
}
